package com.hzx.shoot;

import com.hzx.shoot.img.Images;

import java.awt.image.BufferedImage;

/*
 * 敌人类 :小蜜蜂
 * */
public class Bee extends FlyingObject {

    @Override
    public String toString() {
        return "Bee{" +
                "xSpeed=" + xSpeed +
                ", ySpeed=" + ySpeed +
                ", index=" + index +
                ", wdith=" + wdith +
                ", height=" + height +
                ", x=" + x +
                ", y=" + y +
                '}';
    }

    //速度
    public int xSpeed;
    public int ySpeed;

    public Bee() {
/*        this.wdith = 60;
        this.height = 43;
        this.x= (int)(Math.random()*(512-this.wdith));
        this.y = -this.height;*/
        super(60, 43);

        xSpeed = 3;
        ySpeed = 2;
    }

    int index = 0; //=1

    @Override
    public BufferedImage getImage() {
        //游戏开始运行的状态应该为第一张
        if (state == LIVE) {
            //如果活的就要返回第一张图
            return Images.beeImage[0];
        } else if (state == DEAD) {
            BufferedImage image = Images.beeImage[++index];//index++
            if (index == Images.beeImage.length) {//图片如果遍历到最后一张 就可以吧当前的对象进行移除
                state = REMOVE;
            }
            return image;
        }
        return null;
    }

    @Override
    public void step() {
        this.x += xSpeed;
        this.y += ySpeed;
        //判断是否要反向
        if (x > World.WIDTH - this.wdith || x < 0) {
            //xSpeed = -xSpeed;//xspeed *=-1;超出界面 所以要加负值进行减少
            xSpeed *= -1;
        }


    }
}
